function BangoAgent()
{

}

BangoAgent.prototype.bangoLogger = new BangoLogger();
BangoAgent.prototype.userAgent = null;

/**
 * The method used to distribute the application.
 *
 * @param applicationChannel
 *            The method used to distribute the application, for example
 *            "AppStore".
 */
BangoAgent.setApplicationChannel = function(applicationChannel)
{
    _bangoAgent.bangoLogger.applicationChannel(applicationChannel);
};

/**
 * Gets the method used to distribute the application.
 *
 * @return The method used to distribute the application, for example
 *         "AppStore".
 */
BangoAgent.getApplicationChannel = function()
{
    return _bangoAgent.bangoLogger.applicationChannel();
};

/**
 * The type of application.
 *
 * @param applicationType
 *            The type of application, for example "Lite".
 */
BangoAgent.setApplicationType = function(applicationType)
{
    _bangoAgent.bangoLogger.applicationType(applicationType);
};

/**
 * Gets the type of application.
 *
 * @return The type of application, for example "Lite"
 */
BangoAgent.getApplicationType = function()
{
    return _bangoAgent.bangoLogger.applicationType();
};

/**
 * The application version to be used, if this is not supplied then the
 * application version number of the application is used.
 *
 * @param applicationVersion
 *            The application version to be used.
 */
BangoAgent.setApplicationVersion = function(applicationVersion)
{
    _bangoAgent.bangoLogger.applicationVersion(applicationVersion);
};

/**
 * Gets the application version to be used.
 *
 * @return The application version to be used.
 */
BangoAgent.getApplicationVersion = function()
{
    return _bangoAgent.bangoLogger.applicationVersion();
};

/**
 * The period in seconds, that after we receive onSessionEnd call we will
 * still count events in that of the previous session.
 *
 * @param continueSessionSeconds
 *            This is the period in seconds.
 */
BangoAgent.setContinueSessionSeconds = function(continueSessionSeconds)
{
    _bangoAgent.bangoLogger.sessionResumePeriod(continueSessionSeconds);
};

/**
 * Gets the period in seconds, that after we receive onSessionEnd call we
 * will still count events in that of the previous session.
 *
 * @return The period in seconds.
 */
BangoAgent.getContinueSessionSeconds = function()
{
    return _bangoAgent.bangoLogger.sessionResumePeriod();
};

/**
 * Whether or not an attempt should be made to discover the
 * user’s location, by default this is set to true.
 *
 * @param findLocation
 * 			Should location data be found.
 */
BangoAgent.setFindLocation = function(findLocation)
{
    _bangoAgent.bangoLogger.findLocation(findLocation);
};

/**
 * Gets whether or not an attempt should be made to discover the user's
 * location.
 *
 * @return Whether or not an attempt should be made to discover the user's
 *         location.
 */
BangoAgent.getFindLocation = function()
{
    return _bangoAgent.bangoLogger.findLocation();
};

/**
 * Enables or disables the logging of events.
 *
 * @param logEvents
 *            Should events be logged.
 */
BangoAgent.setLogEnabled = function(logEvents)
{
    _bangoAgent.bangoLogger.logEvents(logEvents);
};

/**
 * Gets whether not events are being logged.
 *
 * @return Whether not events are being logged.
 */
BangoAgent.getLogEnabled = function()
{
    return _bangoAgent.bangoLogger.logEvents();
};

/**
 * Sets the URL to post the data to.
 *
 * @param postURL
 *            The URL to post the data to.
 */
BangoAgent.setPostURL = function(postURL)
{
    _bangoAgent.bangoLogger.postURL(postURL);
};

/**
 * Gets the URL to post the data to.
 *
 * @return The URL to post the data to.
 */
BangoAgent.getPostURL = function()
{
    return _bangoAgent.bangoLogger.postURL();
};

BangoAgent.setUseOfflineStorage = function(useOfflineStorage)
{
    _bangoAgent.bangoLogger.useOfflineStorage(useOfflineStorage);
};

BangoAgent.getUseOfflineStorage = function()
{
    return _bangoAgent.bangoLogger.useOfflineStorage();
};

/**
 * The unique identifier that you have for the user of the application. For
 * example, this could be an email or a GUID or just a numerical value.
 *
 * @param userId
 */
BangoAgent.setUserId = function(userId)
{
    _bangoAgent.bangoLogger.userId(userId);
};

/**
 * Gets the unique identifier for the user of the application
 *
 * @return The unique identifier for the user.
 */
BangoAgent.getUserId = function()
{
    return _bangoAgent.bangoLogger.userId();
};

BangoAgent.onStartSession = function(applicationKey, eventValue, eventDetail, eventParameters)
{
	if (!(applicationKey) || (applicationKey == ""))
	{
		throw "Api key not specified";
		return;
	}

    _bangoAgent.bangoLogger.initLogger(applicationKey);
    _bangoAgent.bangoLogger.logEventStart(eventValue, eventDetail, eventParameters);
	_bangoAgent.bangoLogger.postEvents(false, true);
};

BangoAgent.onEndSession = function(forceEventPosting, eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.SESSION_END(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }

	if (forceEventPosting)
	{
		_bangoAgent.bangoLogger.postEvents(true, false);
	}

};

BangoAgent.onPageView = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_PAGEVIEW(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onSearch = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_SEARCH(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onLiveVideoStart = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        if (eventParameters == null)
        {
            eventParameters = new Array();
        }
        eventParameters.push(new BangoEventParameter(BangoConstants.VIDEO_PARAMETERNAME(), BangoConstants.VIDEO_LIVEPARAMETER()));
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_VIDEOSTART(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
		_bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onLiveVideoStop = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        if (eventParameters == null)
        {
            eventParameters = new Array();
        }
        eventParameters.push(new BangoEventParameter(BangoConstants.VIDEO_PARAMETERNAME(), BangoConstants.VIDEO_LIVEPARAMETER()));
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_VIDEOSTOP(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onDemandVideoStart = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        if (eventParameters == null)
        {
            eventParameters = new Array();
        }
        eventParameters.push(new BangoEventParameter(BangoConstants.VIDEO_PARAMETERNAME(), BangoConstants.VIDEO_ONDEMANDPARAMETER()));
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_VIDEOSTART(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onDemandVideoStop = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        if (eventParameters == null)
        {
            eventParameters = new Array();
        }
        eventParameters.push(new BangoEventParameter(BangoConstants.VIDEO_PARAMETERNAME(), BangoConstants.VIDEO_ONDEMANDPARAMETER()));
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.EVENT_VIDEOSTOP(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onIdle = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.SESSION_IDLE_START(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onResume = function(eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(BangoSessionEvents.SESSION_IDLE_END(), eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onEvent = function(eventName, eventValue, eventDetail, eventParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEvent(eventName, eventValue, eventDetail, eventParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorWarning(ex);
    }
};

BangoAgent.onError = function(errorId, message, errorClass, errorParameters)
{
    try
    {
        _bangoAgent.bangoLogger.logEventError(errorId, message, errorClass, errorParameters);
    }
    catch (ex)
    {
        _bangoAgent.bangoLogger.logInternalErrorCritical(ex);
    }
};

BangoAgent.postEvents = function()
{
	_bangoAgent.bangoLogger.postEvents(true, true);
};

BangoAgent.viewBatch = function()
{
	return JSON.stringify(BangoStorage.getBatch());
}

var _bangoAgent = new BangoAgent();


